(function (window, $, undefined) {
  'use strict';

  var historyGetData = {};

  main(function () {

    var $tableHistoryGet = $('#table-history-get');

    util.jqGrid($tableHistoryGet, {
      url: ajaxURL.COUPON + '/coupon/v1/userPlan/queryPushWithPage',
      mtype: 'POST',
      autowidth: true,
      height: $(window).height() - 320,
      multiselect: true,
      multiboxonly: true,
      // shrinkToFit: false,
      colModel: [
        { name: 'kid', key: true, hidden: true },
        { label: '序号', name: 'kid', width: 50, fixed: true },
        { label: '用户ID', name: 'userId', hidden: true, width: 100 },
        { label: '用户名', name: 'userName', width: 100 },
        { label: '用户电话', name: 'phone', width: 100 },
        { label: '领取方案', name: 'planId', width: 200 },
        {
          label: '领取时间', name: 'createTime', width: 100, formatter: function (v) {
            return util.dateFormat(v);
          } }
      ],
      loadComplete: function (res) {
        historyGetData = {};
        if (res && res.data) {
          $.each(res.data, function (_, item) {
            historyGetData[item.kid] = item;
          });
        }
      },
      pager: '#pager-history-get'
    }, true);

    searchTable();

    // 搜索
    function searchTable() {
      var data = util.formData('#form-search');
      if (data.createTime) {
        var temp = data.createTime.split(' 至 ');
        data.pullStartDate = temp[0]; // util.getTime(temp[0] + ' 00:00:00');
        data.pullEndDate = temp[1]; // util.getTime(temp[1] + ' 23:59:59');
      }

      delete data.createTime;

      util.searchGrid($tableHistoryGet, data);
    }

    $('#btn-search').click(searchTable);

    laydate.render({
      elem: '#createTime',
      range: '至'
    });

  });

})(window, jQuery);
